package com.estore.converter;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import freemarker.template.utility.DateUtil;

public class DateTime {
	public String currentDate() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date date = new Date();
		String currentDate = dateFormat.format(date);
		return currentDate;
	}

	public String currentDay() {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		String currentDate = dateFormat.format(date);
		return currentDate;
	}
	
	public String getDate(Integer year, Integer month, Integer day) {
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date(year, month, day);
		String getDate = dateFormat.format(date);
		return getDate;
	}

	public String endDate(Integer duration){
		Calendar calendar = new GregorianCalendar();
		calendar.add(calendar.DATE, duration);
		Date d = calendar.getTime();
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		String endDate = dateFormat.format(d);
		return endDate;
	}
	
	public int dayLeft(String endDate) throws ParseException{
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date = new Date();
		Date end = dateFormat.parse(endDate);
		
		long diff = end.getTime() - date.getTime();
		int diffDays = (int) Math.ceil((double) diff / (24 * 60 * 60 * 1000));
		return diffDays;
	}
	
	public String showDate(String birthDay) {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
		String showDate = "";
		try {
			Date date = dateFormat.parse(birthDay);
			showDate = dateFormat.format(date);
		} catch (Exception e) {
			System.out.println(e);
		}
		return showDate;
	}

	public String addImgDate() {
		DateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		Date date = new Date();
		String getDate = dateFormat.format(date);
		return getDate;
	}
}
